import 'package:flutter/material.dart';

class BlinkingPlaceholder extends StatefulWidget {
  final Color color;
  const BlinkingPlaceholder({super.key, required this.color});

  @override
  State<BlinkingPlaceholder> createState() => _BlinkingPlaceholderState();
}

class _BlinkingPlaceholderState extends State<BlinkingPlaceholder>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<double> _opacity;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(milliseconds: 900), // 更柔和
      vsync: this,
    )..repeat(reverse: true);
    _opacity = CurvedAnimation(
      parent: _controller,
      curve: Curves.easeInOut, // 丝滑曲线
    ).drive(Tween<double>(begin: 0.4, end: 1.0)); // 透明度范围更大
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return FadeTransition(
      opacity: _opacity,
      child: Container(
        width: double.infinity,
        height: double.infinity,
        color: widget.color,
      ),
    );
  }
}
